package consultan.vanke.com.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

import consultan.vanke.com.R;

public class CommonDialogCheck1 extends Dialog {
    private TextView tv_cancle;
    private boolean isannotation;
    private Context context;
    private TextView tv_ok;

    private onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器
    private onCancleOnclickListener cancleOnclickListener;//确定按钮被点击了的监听器

    public CommonDialogCheck1(Context context, boolean isannotation) {
        super(context, R.style.MyDialog);
        this.isannotation = isannotation;
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View inflate = LayoutInflater.from(context).inflate(R.layout.common_dialog_check1, null);
        setContentView(inflate);
        //放大动画
        if (isannotation) {
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.common_dialog);
            inflate.setAnimation(animation);
            animation.start();
        }
        initView();
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件的事件
        initEvent();

    }

    private void initView() {
        tv_cancle = findViewById(R.id.tv_cancle);
        tv_ok = findViewById(R.id.tv_ok);
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        //设置确定按钮被点击后，向外界提供监听
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (yesOnclickListener != null) {
                    yesOnclickListener.onYesClick();
                }
            }
        });
        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cancleOnclickListener != null) {
                    cancleOnclickListener.onCancleClick();
                }
            }
        });
    }


    /**
     * 设置确定按钮和取消被点击的接口
     */
    public interface onYesOnclickListener {
        public void onYesClick();
    }

    public interface onCancleOnclickListener {
        public void onCancleClick();
    }


    public void setYesOnclickListener(onYesOnclickListener onYesOnclickListener) {
        this.yesOnclickListener = onYesOnclickListener;
    }

    public void setCancleOnclickListener(onCancleOnclickListener oncancleOnclickListener) {
        this.cancleOnclickListener = oncancleOnclickListener;
    }
}
